package org.tysite.tyservice.example.validation.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 名称验证的注解解析器
 * @author tysite
 * @date 2020/3/22 0022 20:37
 */
public class DemoNameValidator implements ConstraintValidator<DemoName, CharSequence> {
    
    @Override
    public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
        if ( value == null ) {
            return false;
        } else {
            Integer charLength = value.toString().trim().length();
            if (charLength >= 1 && charLength <= Constant.NAME_MAX) {
                return true;
            } else {
                return false;
            }
        }
    }
}
